<?php

$root = dirname(__FILE__);
define('BASEPATH', $root.'/');
require_once $root.'/function.php';
require_once $root.'/config.php';
require_once $root.'/model.php';


$model = new Model();

//獲取中轉站的server信息
$baseServer = $model->getBaseServer();
initBaseServerInfo($baseServer);

$count = 100;
$list = $model->getDelAvFileList($count);
if(count($list) < 1){
  echo "\n===== 待刪檔隊列為NULL.睡一會繼續! ======\n";
  sleep(600);
  die(0);
}
foreach($list as $val){
  $storageServer = $model->getStorageServerBySid($val['serverid']);
//var_dump($storageServer);exit;
  if( !isset($storageServer['serverid'])){
    die("\n=====The storageServer serverid is Empty!====\n");
  }
  $status = deleteAvFilesByAvkey($val);
  usleep(300000);
  if($status){
    //刪除成功 
    $model->setAvStatusByAvkey($val['avkey'], 8);
  }else{
    $model->setAvStatusByAvkey($val['avkey'], 9);
  }
}
echo "\n===== 任務執行完畢暫停.歇一會繼續! =======\n";
sleep(60);
